package com.lpf.db_pools;

import lombok.Data;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 连接池内的自定义管道对象
 */
@Data
public class PooledConnection {

    // 里面封装的是真正的物理连接对象
    private Connection conn;

    // 定义一个标示 标示它是否繁忙 是否被占用
    private boolean isBusy = false;

    public PooledConnection(Connection conn, boolean isBusy) {
        this.conn = conn;
        this.isBusy = isBusy;
    }

    // 关闭连接
    public void close() {
        this.isBusy = false;
    }

    /**
     * 自定义查询方法
     */
    public ResultSet queryBySql(String sql) {
        Statement sm;
        ResultSet rs = null;
        try {
            sm = conn.createStatement();
            rs = sm.executeQuery(sql);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return rs;
    }
}
